package fr.upmc.cie.ext;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html.ImageGetter;

public class RemoteImageGetter implements ImageGetter {

	@Override
	public Drawable getDrawable(String source) {
		Bitmap bmImg;
		URL myFileUrl =null;          
        try {
        	myFileUrl= new URL(source);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();
            
            bmImg = BitmapFactory.decodeStream(is);
            BitmapDrawable bd = new BitmapDrawable(bmImg);
            bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
     		return bd;
        } catch (IOException e) {
             e.printStackTrace();
        }
        return null;

	}

}
